<template>
    <div>
        <h1>修改</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td align="right">房型名称</td>
                    <td><input type="text" v-model="info.Name"></td>
                </tr>
                <tr>
                    <td align="right">发布状态</td>
                    <td><input type='radio' name="set" v-model="info.FXZT" :value="true">发布
                        <input type="radio" name="set" v-model="info.FXZT" :value="false">不发布</td>
                </tr>
                <tr>
                    <td align="right">上架状态</td>
                    <td><input type='radio' name="set1" v-model="info.SJZT" :value="true">上架
                        <input type="radio" name="set1" v-model="info.SJZT" :value="false">不上架</td>
                </tr>
                <tr>
                    <td align="right">图片</td>
                    <td><input type="file" @change="imgs">
                        <img :src="info.Img" width="100" height="100">
                    </td>
                </tr>
                <tr>
                    <td align="right">创建时间</td>
                    <td><input type="date" v-model="info.CountTime"></td>
                </tr>
                <tr>
                    <td align="right">面积</td>
                    <td><input type="text" v-model="info.Mianji"></td>
                </tr>
                <tr>
                    <td align="right"></td>
                    <td><input type="button" value="修改" @click="ok"></td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import{ref, reactive,onMounted} from 'vue'
import axios from 'axios';
import { useRouter,useRoute } from 'vue-router';
import moment from 'moment';
const router=useRouter();
const route=useRoute();
let info:any=reactive({
  Id: route.query.id,
  Name: '',
  FXZT: '',
  SJZT: '',
  Img:'',
  CountTime: '',
  Mianji: 0,
})
onMounted(()=>{
    getFind();
})
const getFind=()=>{
    axios({
        url:'/api/FX/Find',
        method:'get',
        params:{
            id:route.query.id
        }
    })
    .then((res)=>{
        console.log(res);
        Object.assign(info,res.data);
        info.CountTime=res.data.CountTime.substring(0,10)
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
const imgs=(e:any)=>{
    let obj=e.target.files[0];
    let f = new FormData();
    f.append('file',obj);
    axios({
        url:'/api/Img/Img',
        method:'post',
        data:f
    })
    .then((res)=>{
        console.log(res);
        if(res.data=="不是图片")
    {
         alert("你上传的不是图片")
    }
    if(res.data=='大于2M')
    {
        alert("你上传的大于2M")
    }
    info.Img=res.data;
    })
    .catch((err)=>{
        console.log(err);
        
    })
}
const ok=()=>{
axios({
    url:'/api/FX/updateFX',
    method:'put',
    data:info
})
.then((res)=>{
    console.log(res);
    if(res.data==-1)
{
    alert('有重复值')
    return
}
if(res.data>0)
{
    alert('修改成功');
    return;
}
else
{
    alert('修改失败');
    return;
}
})
.catch((err)=>{
    console.log(err);
    
})

}
</script>

<style scoped>

</style>